import request from "@/utils/request";

/**
 * 登录
 * @param phone 
 * @param username 
 * @param password 
 * @param code 
 * @returns 
 */
export const login = (phone: String, username: String, password: String, code: String) => {
    return request.post(`/user/login?code=${code}`, {
        phone: phone,
        username: username,
        password: password
    })
}

/**
 * 注册
 * @param phone 、
 * @param password 
 * @returns 
 */
export const register = (phone: String, password: String): Promise<any> => {
    return request.post(`/user/register`, {
        phone: phone,
        password: password
    });
}

/**
 * 获取用户信息
 * @param userId 
 * @returns 
 */
export const getUserInformation = (userId: Number) => {
    return request.get(`/user/userinfo/${userId}`)
}

/**
 * 获取权限菜单
 * @param roleId 
 * @returns 
 */
export const getMenuByRoleId = (roleId: Number) => {
    return request.get(`/menu/${roleId}`)
}

/**
 * 根据id删除单个用户
 * @param userId 
 * @returns 
 */
export const deleteUserById = (userId: Number) => {
    return request.delete(`/user/${userId}`)
}

/**
 * 分页获取用户信息
 * @param pageCurrent 
 * @param pageSize 
 * @returns 
 */
export const getUserListByPage = (pageCurrent: Number, pageSize: Number) => {
    return request.get(`/user/page?pageCurrent=${pageCurrent}&pageSize=${pageSize}`);
}

interface User {
    id: number,
    username: String,
    nickName: String,
    realName: String,
    phone: String,
    email: String,
    address: String,
    roleId: number | string
}

interface editUser {
    id: number,
    username: String,
    nickName: String,
    realName: String,
    phone: String,
    email: String,
    address: String,
    roleId: number | string
}

/**
 * 添加用户
 * @param user 
 * @returns 
 */
export const addUser = (user: User) => {
    return request.put(`/user`, {
        nickName: user.nickName,
        realName: user.realName,
        phone: user.phone,
        email: user.email,
        address: user.address,
        roleId: user.roleId
    })
}
/**
 * 编辑用户
 */
export const editUser = (user: editUser) => {
    return request.post(`/user`, {
        id: user.id,
        username: user.username,
        nickName: user.nickName,
        realName: user.realName,
        phone: user.phone,
        email: user.email,
        address: user.address,
        roleId: user.roleId
    })
}

export const pretendDeleteUser = (userId: number) => {
    return request.delete(`/user/${userId}`)
}